<?
include('adodb/adodb-exceptions.inc.php'); 
require ("comun/ini.php");
if(isset($_POST['JsonEnv'])){
	$JsonEnv = new Services_JSON();
	$JsonRec = new Services_JSON();
	$JsonRec=$JsonRec->decode(str_replace("\\","",$_POST['JsonEnv']));	
	try {
		$q = "SELECT B.id AS id_concepto, to_char(A.fecha, 'mm/yyyy') AS periodo, B.nombre AS nombre_concepto, COALESCE(SUM(A.saldo),0) AS saldo 
			  FROM cxc_peritos AS A 
				INNER JOIN conceptos AS B ON A.id_concepto = B.id 
			WHERE A.saldo>0 AND A.estatus='P' AND A.id_perito=$JsonRec->Perito GROUP BY B.nombre, B.id, to_char(A.fecha, 'mm/yyyy')  ORDER BY to_char(A.fecha, 'mm/yyyy') , B.nombre";			
			
		$r = $conn->Execute($q);
		$i=0;
		while(!$r->EOF){
			$Deuda[$i]['ID'] = (int)$r->fields['id_concepto'];
			$Deuda[$i]['C'] = $r->fields['nombre_concepto'];
			$Deuda[$i]['M'] = muestrafloat($r->fields['saldo']);
			$Deuda[$i]['P'] = $r->fields['periodo'];

			$i++;
			$r->movenext();
		}
		if(is_array($Deuda)){
			echo $JsonEnv->encode($Deuda);
		}else{
			echo false;
		}
	}catch( ADODB_Exception $e ){
		//	echo ERROR_CATCH_GENERICO;
		echo false;
	}
}
?>